<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js"></script>
</head>

<body>
    <div class="app">
        <input type="text" v-model="keyword">{{keyword}}
        <ul>
            <li v-for="(item,index) in filperson" :key="index"> {{item.name}}-{{item.age}}</li>
        </ul>
    </div>
    <script>
        const vm = new Vue({
            data: {
                person: [{
                    name: '周杰伦',
                    age: 18
                }, {
                    name: '马冬梅',
                    age: 19
                }, {
                    name: '周冬雨',
                    age: 20
                }, {
                    name: '张鹤伦',
                    age: 21
                }],
                keyword: "",
                filperson: []
            },
            watch: {
                keyword: {
                    immediate: true,
                    handler(val) {
                        console.log(val);
                        this.filperson = this.person.filter((v) => {
                            return v.name.indexOf(val) != -1
                        })
                    }
                }
            }
        }).$mount(".app")
    </script>
</body>

</html>